<?php

use think\migration\Migrator;
use think\migration\db\Column;

class Contract extends Migrator
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
     *
     * The following commands can be used in this method and Phinx will
     * automatically reverse them when rolling back:
     *
     *    createTable
     *    renameTable
     *    addColumn
     *    renameColumn
     *    addIndex
     *    addForeignKey
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change()
    {
        $this->table('contract', ['comment' => '合同', 'id' => false])
            ->addColumn('id', 'integer', ['limit' => \Phinx\Db\Adapter\MysqlAdapter::INT_REGULAR, 'identity' => true, 'signed' => false])
            ->addColumn('name', 'string', ['limit' => 100, 'default' => '', 'comment' => '合同名称'])
            ->addColumn('project_id', 'integer', ['limit' => 10, 'default' => '0', 'comment' => '所属项目ID'])
            ->addColumn('price', 'decimal', ['precision' => 10, 'scale' => 2, 'signed' => false, 'default' => '0.00', 'comment' => '合同金额'])
            ->addColumn('develop_time_start', 'integer', ['signed' => false, 'default' => 0, 'comment' => '开发周期开始时间'])
            ->addColumn('develop_time_end', 'integer', ['signed' => false, 'default' => 0, 'comment' => '开发周期结束时间'])
            ->addColumn('status', 'integer', ['limit' => \Phinx\Db\Adapter\MysqlAdapter::INT_TINY, 'default' => '0', 'comment' => '项目状态'])
            ->addColumn('pay_type', 'integer', ['limit' => \Phinx\Db\Adapter\MysqlAdapter::INT_TINY, 'default' => '0', 'comment' => '付费方式'])
            ->addColumn('linker_name', 'string', ['limit' => 100, 'default' => '', 'comment' => '对接人'])
            ->addColumn('linker_phone', 'string', ['limit' => 100, 'default' => '', 'comment' => '对接人电话'])
            ->addColumn('document_path', 'string', ['limit' => 200, 'default' => '', 'comment' => '需求文档地址'])
            ->addColumn('contract_path', 'string', ['limit' => 200, 'default' => '', 'comment' => '合同文件地址'])
            ->addColumn('remark', 'text', ['limit'=>MysqlAdapter::TEXT_LONG,'comment'=>'消息'])
            ->addColumn('create_time', 'integer', ['signed' => false, 'default' => 0, 'comment' => '创建时间'])
            ->addColumn('update_time', 'integer', ['signed' => false, 'default' => 0, 'comment' => '修改时间'])
            ->addColumn('delete_time', 'integer', ['signed' => false, 'default' => 0, 'comment' => '删除时间'])
            ->setPrimaryKey('id')
            ->create();


        $this->table('contract_price', ['comment' => '合同金额', 'id' => false])
            ->addColumn('id', 'integer', ['limit' => \Phinx\Db\Adapter\MysqlAdapter::INT_REGULAR, 'identity' => true, 'signed' => false])
            ->addColumn('contract_id', 'integer', ['limit' => \Phinx\Db\Adapter\MysqlAdapter::INT_REGULAR, 'signed' => false, 'comment' => '合同ID'])
            ->addColumn('label', 'string', ['limit' => 200, 'default' => '', 'comment' => '款项名称'])
            ->addColumn('price', 'decimal', ['precision' => 10, 'scale' => 2, 'signed' => false, 'default' => '0.00', 'comment' => '应付金额'])
            ->addColumn('payment', 'decimal', ['precision' => 10, 'scale' => 2, 'signed' => false, 'default' => '0.00', 'comment' => '已付金额'])
            ->addIndex(array('contract_id','label'), array('unique'  =>  true))
            ->setPrimaryKey('id')
            ->create();
    }
}
